import './assets/css/style.css';
import xmind from './assets';

let nodes = [
    {id:"root",label:"根节点",root:true,pull:{
        l:null,
        r:{
            show:null,
            plus:false,
            has:null,
        },
        // divColor:"#f00",
    }},
    {id:"r1",label:"落花生落花生落花生落花生落花生落花生落花生落花生落花生落花生落花生",html:"",pid:"root",flip:false,status:1,nodeLimit:200,
        pull:{r:{plus:false}}
        // ,divColor:"#f00",
        // divBgColor:"#000"
    },
    {id:"r11",label:"右11",pid:'r1',flip:false,type:'tree',status:1},
    {id:"r12",label:"右12",pid:"r1",flip:false},
    {id:"r123",label:"右123",pid:"r12",flip:false},
    {id:"r2",label:"右2",type:"compute",pid:"root",flip:false},
    {id:"r21",label:"右21",type:"compute",pid:"r2",flip:false},
    {id:"l1",label:"左1",pid:"root",flip:true},
    {id:"l11",label:"左11",pid:"l1",flip:true},
    {id:"l2",label:"左2",pid:"root",flip:true},
];

let $xmind2 = new xmind({
    selector:"xmind",
    // data:nodes,
    style:{
        node:{
            rule:{
                icon:"test-icon1",
                cls:"ruleCls",
            },
            compute:{
                icon:"computeIcon",
                cls:"computeCls",
            }
        }
    },
    // nodeLimit:200
    onload:()=>{
        setTimeout(()=>{
            $xmind2.updateNode({
                id:'r1',
                divClass:['aaa','bbb','ccc'],
                status:1,
                // nodeLimit:500
            })

            $xmind2.clearStatus();
            console.log($xmind2.getNodes())
        })
        
        // setTimeout(()=>{
        //     $xmind2.updateNode({
        //         id:'r1',
        //         divClass:['aaa','bbb','ccc'],
        //         status:1,
        //     })

        //     $xmind2.clearStatus();
        // })
        
    }
})

$xmind2.setNodes({
    items:nodes,
});

$xmind2.getNodes();



// $xmind2.updateNode({
//     id:'r1',
//     label:'r2',
// })

// $xmind2.setZoom(1.5)

window.onload = ()=>{
    let devTest = document.getElementById('test');
    devTest.onmousedown = e=>{
        // $xmind2.localRoot();
        // $xmind2.createdDragNode({
        //     id:"new"+(new Date()).getTime(),
        //     e,
        //     label:"新节点1",
        //     nodeType:"compute",
        //     data:{a:1}
        // });
        console.log($xmind2.getNodes()[0])
    }

    let elnarrow = document.getElementById('narrow');
    elnarrow.onclick = e=>{
        console.log('narrow')
        $xmind2.hawkEye(true,'narrow');
        return;
        $xmind2.setNodes({
            items:nodes,
            fn:()=>{
                console.log($xmind2.getZoom())
            }
        });
    }
}

$xmind2.setContentMenu({
    type:"canvas",
    items:[
        {label:"新建方案",id:"add",name:"canvas",fn:(res)=>{
            console.log('rbb',res)
        }},
        {label:"收起全部节点",id:"pull1",name:"canvas",fn:(res)=>{
            // console.log('收起节点',res)
            $xmind2.setPull({
                type:'all',
                flip:null,
                // pull:'auto',
                // name:'childrenPull'
            })
        }},
        {label:"收起1级节点",id:"pull2",name:"canvas",fn:(res)=>{
            // console.log('收起1级节点',res)
            $xmind2.setPull({
                type:1,
                flip:false,
                // pull:'auto',
                // name:'childrenPull'
            })
        }},
        {label:"收起2级节点",id:"pull3",name:"canvas",fn:(res)=>{
            // console.log('收起节点',res)
            $xmind2.setPull({
                type:2,
                flip:false,
                // pull:'auto',
                // name:'childrenPull'
            })
        }}
    ],
});

$xmind2.setContentMenu({
    type:"node",
    items:[
        {label:"新建节点",id:"addNode",name:"node",fn:(res)=>{
            console.log(res)
            let pidData = res.data;
            $xmind2.addNode({
                id      : "node_" + (new Date).getTime(),
                pid     : pidData.id,
                flip    : pidData.flip,
            });
            $xmind2.setNodeCheckeds([]);
        }},
        {label:"删除节点",id:"delNode",name:"node",fn:(res)=>{
            let pidData = res.data;
            $xmind2.delNode({
                id      : pidData.id,
            });
        }},
        {label:"关联节点",id:"automaticNode",name:"node",fn:(res)=>{
            let pidData = res.data;
            $xmind2.contactLine(res.data.id);
        }},
        {label:"收起节点",id:"pushNode",name:"node",fn:(res)=>{
            console.log('收起节点');
            if(res.data.id === 'root'){
                $xmind2.pullNode({
                    id:res.data.id,
                    flip:false,
                    // name:'childrenPull'
                });
            }
            else{
                $xmind2.pullNode({
                    id:res.data.id
                });
            }
            
        }},
        // {label:"展开节点",id:"pullNode",name:"node",fn:(res)=>{
        //     console.log('展开节点');
        //     $xmind2.clearConTactLine();
        // }},
        {
            label:"1级",id:"one",name:"node",children:[
                {
                    label:"2级",id:"two",name:"node",fn:(res)=>{
                        console.log('展开二级',res);
                    }
                },
                {
                    label:"3级",id:"two2",name:"node",fn:(res)=>{
                        console.log('展开3级',res);
                    }
                }
            ]
        },
        {
            label:"11级",id:"one2",name:"node",children:[
                {
                    label:"21级",id:"two22",name:"node",fn:(res)=>{
                        console.log('展开二1级',res);
                    }
                },
                {
                    label:"31级",id:"two222",name:"node",fn:(res)=>{
                        console.log('展开31级',res);
                    }
                }
            ]
        }
    ],
});

$xmind2.on('nodeClick',(e,r)=>{
    console.log('nodeClick',e,r,$xmind2.getNode('r1'));
    console.log('getNodeCheckeds',$xmind2.getNodeCheckeds())
})

$xmind2.on('canvasDrag',(e,r)=>{
    console.log('canvasDrag',r);
    // console.log($xmind2.getNode(r.data.id))
})

$xmind2.on('cntMenuNode',(e,r)=>{
    console.log('cntMenuNode',r,$xmind2.getNodes()[0]);
    
})

$xmind2.on('nodeDel',(e,r)=>{
    console.log('nodeDel',r);
})

$xmind2.drawContactLine({
    startId:"r11",
    endId:"r12",
})


// $xmind2.clear();

